package com.sample.library.web;

import android.content.Context;
import android.webkit.JavascriptInterface;


/**
 * Created by Administrator on 2017/2/10.
 */

public class AndroidInterface {
    private Context context;
    private String[] imageUrls;

    public AndroidInterface(Context context, String[] imageUrls) {
        this.context = context;
        this.imageUrls = imageUrls;
    }

    @JavascriptInterface
    public void openImage(String img) {
        System.out.println(img);
//        Intent intent = new Intent();
//        intent.putExtra("imageUrls", imageUrls);
//        intent.putExtra("curImageUrl", img);
//        intent.setClass(context, PhotoBrowserActivity.class);
//        context.startActivity(intent);
    }

//    public static String[] returnImageUrlsFromHtml() {
//        List<String> imageSrcList = new ArrayList<String>();
//        String htmlCode = returnExampleHtml();
//        Pattern p = Pattern.compile("<img\\b[^>]*\\bsrc\\b\\s*=\\s*('|\")?([^'\"\n\r\f>]+(\\.jpg|\\.bmp|\\.eps|\\.gif|\\.mif|\\.miff|\\.png|\\.tif|\\.tiff|\\.svg|\\.wmf|\\.jpe|\\.jpeg|\\.dib|\\.ico|\\.tga|\\.cut|\\.pic|\\b)\\b)[^>]*>", Pattern.CASE_INSENSITIVE);
//        Matcher m = p.matcher(htmlCode);
//        String quote = null;
//        String src = null;
//        while (m.find()) {
//            quote = m.group(1);
//            src = (quote == null || quote.trim().length() == 0) ? m.group(2).split("//s+")[0] : m.group(2);
//            imageSrcList.add(src);
//        }
//        if (imageSrcList == null || imageSrcList.size() == 0) {
//            Log.e("imageSrcList", "资讯中未匹配到图片链接");
//            return null;
//        }
//        return imageSrcList.toArray(new String[imageSrcList.size()]);
//    }
}
